package cn.flying.cloud.system.view;

import javax.annotation.Resource;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.flying.cloud.system.common.service.CodeService;
import cn.flying.cloud.system.user.entity.SysUserInfo;
import cn.flying.cloud.system.user.service.SysUserInfoService;

/**
 * @description: 系统用户信息请求处理器
 * @author: admin
 * @date: 2022年05月22日 17:52
 * @version: 1.0
 */
@Controller
@RequestMapping("/sys/user/")
public class SysUserViewController {

    @Resource
    private SysUserInfoService sysUserInfoService;
    @Resource
    private CodeService codeService;

    /**
     * 跳转到列表页面
     *
     * @return
     */
    @RequestMapping("index")
    public String list(Model model) {
        Map<String, String> statusList = codeService.getCodeList("status");
        model.addAttribute("statusList", statusList);
        return "sys/user/index";
    }

//    /**
//     * 获取用户下拉框数据 xm-select
//     *
//     * @param
//     * @return
//     */
//    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
//    @ResponseBody
//    public Rt<List<XmSelect>> getSelectList() {
//        List<XmSelect> list = sysUserInfoService.getUserSelectList();
//        return Rt.success(list);
//    }

    /**
     * 新增/修改页面
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("turn/edit")
    public String turnEdit(Long id, Model model) {
        Map<String, String> genderList = codeService.getCodeList("gender");
        model.addAttribute("genderList", genderList);
        if (null != id) {
            SysUserInfo userInfo = sysUserInfoService.getById(id);
            model.addAttribute("user", userInfo);
        } else {
            model.addAttribute("user", new SysUserInfo());
        }
        return "sys/user/edit";
    }

//    /**
//     * 修改密码
//     *
//     * @return
//     */
//    @RequestMapping("updatePwd")
//    @ResponseBody
//    public Rt updatePwd(@Validated @RequestBody UserPassInfo info) {
//        sysUserInfoService.updatePwd(info);
//        return Rt.success("密码修改成功！");
//    }
//
//    /**
//     * 设置密码
//     *
//     * @return
//     */
//    @RequestMapping("set/password")
//    @ResponseBody
//    public Rt password(@RequestBody SysUserInfo info) {
//        sysUserInfoService.setPwd(info);
//        return Rt.success("密码设置成功！");
//    }

    //        SysUser sysUser = sysUserInfoService.findUserByUserId(info.getUserId());
//        boolean match = passwordEncoderUtil.match(info.getOldPassword(), sysUser.getPassword());
//        if (!match) {
//            throw new BizException("原密码不对，请重新输入！");
//        }
//        String encrypt = passwordEncoderUtil.encrypt(info.getNewPassword());
//        sysUser.setPassword(encrypt);
//        sysUser.setUpdatedBy((String) Ft.ThreadLocal.get(Constants.USER_NAME));
//        sysUser.setUpdatedTime(new Date());
//        sysUserInfoService.updateUserPassword(sysUser);


}

